winPath=F:\project\xiaohan\platform\infra\templates
macPath=/Users/xiaohan/soft/project/xiaohan/zero-bug/1.6.4
buildTime:= $(shell /bin/date "+%Y-%m-%d %H:%M")
version:= $(shell /bin/date "+%Y%m%d%H")
commitId:= $(shell git rev-parse HEAD)
binary=archive
ldflags="-s -w" -ldflags="-X 'main.BuildTime=$(buildTime)' -X 'main.BuildVersion=$(version)' -X 'main.CommitID=${commitId}'"
pid :=  $(shell ps -axf| grep  $(binary) |grep -v grep |awk '{ print $$1 } ')

rpc:
	goctl rpc protoc *.proto --go_out=. --go-grpc_out=. --zrpc_out=. -m -home=$(macPath) -style=go_zero -w=true
model:
	goctl model mysql ddl --src *.sql -c --dir=./internal/model -home=$(macPath) -style=go_zero -prefix=cms -w=true

define run
	rm -rf nohup.out
	if [ -n "$(pid)" ]; then kill -9 $(pid); fi
	nohup ./$(binary) -f etc/prod.yaml &
endef

build:
	go build -ldflags=$(ldflags) $(binary).go
	$(if $(shell command -v upx), upx $(binary))

mac:
	GOOS=darwin go build -ldflags=$(ldflags) -o $(binary) $(binary).go
	$(if $(shell command -v upx), upx $(binary))

win:
	GOOS=windows go build -ldflags=$(ldflags) -o $(binary).exe $(binary).go
	$(if $(shell command -v upx), upx $(binary).exe)
	$(run)

linux:
	GOOS=linux go build -ldflags=$(ldflags) -o $(binary) $(binary).go
	$(run)


